function [a] = of2c_p2(x)
data_struct = load('data2c.mat');
prices = double(data_struct.prices);
nProducts = length(prices);
segQ = double(data_struct.segQ);
segScale = double(data_struct.segScale);
uniqSeg = double(data_struct.uniqSeg);
uniqSeg_size = size(uniqSeg);
nNewSegments = uniqSeg_size(1);
os = double(data_struct.os);
upMat = data_struct.upMat;
[y1,y2,~]=ind2sub(size(upMat),find(upMat));
u = zeros(nNewSegments,3);
for i = 1:nNewSegments
    u(i,:) = [uniqSeg(i,1)+1,y1(i),y2(i)];
end
a = 0;
for i = 1:nNewSegments
    a = a-x(i)*(segScale(u(i,1))*(reallog(1-x(nNewSegments+i))-reallog(x(nNewSegments+i)*exp(1/segScale(u(i,1))*(segQ(u(i,2),u(i,1))-prices(u(i,2))))))+segQ(u(i,3),u(i,1))-prices(u(i,2)));
end
end